
var userName = document.getElementById("userName")
function SetName(){
    userName.innerHTML = window.sessionStorage.getItem("user")
}
SetName()

function path(){
    document.getElementById("SetPath").innerHTML= "/";
}
path()


function creatFile(){
    var msg = prompt("请输入值","预期输入");
    let srcPath = document.getElementById("SetPath").value
    // document.write(msg+"JavaScript输入输出的例子");
    console.log(msg);
}

/* 上传按钮图片设置 */
var reader = new FileReader();
var list = document.getElementById("list");
var lis = list.getElementsByTagName("li");

function uploadFile(e){
    var file = document.getElementById("upfile");
    var value = e.srcElement.files[0];
    reader.readAsDataURL(value);
    reader.onload = function(ev){
        var li = document.createElement("li");
        var img = document.createElement("img");
        img.src= ev.srcElement.result;
        li.appendChild(img);
        list.appendChild(li);
    }
}
// 上传按钮接口设置
var formData = new FormData();
for(var i=0; i<$("#upfile")[0].files.length; i++) {  //循环获取上传个文件
    formData.append("upfile", $("#file")[0].files[i]);
}
// formData.append("bid",bid);//此处可以添加一个参数和图片一起上传
console.log(formData);
$.ajax({
    "url": "http://localhost:8081/user/file/uploadFile",
    "data" : formData,
    "dataType":"json",
    "type": "post",
    // "header":window.sessionStorage.setItem("token"),
    "contentType" : false, //上传文件一定要是false
    "processData":false,
    "success" : function(obj) {
        if (obj.state == 1) {
            layer.alert("上传成功！");
        }else{
            layer.alert(obj.message);
        }
    },
    fetch(data){
        console.log(data)
    }
});
